//
//  DLEmoticon.swift
//  01 表情键盘
//
//  Created by danli on 15/12/28.
//  Copyright © 2015年 danli. All rights reserved.
//

import Foundation

class DLEmoticon: NSObject {
    
    var code:String?{
        didSet{
            // kvc设置code之后,将code转成emoji表情
            // 创建扫描器
            let scanner = NSScanner(string: code!)
            
            // 扫描
            var result: UInt32 = 0
            scanner.scanHexInt(&result)
            let scalar = UnicodeScalar(result)
            
            let c = Character(scalar)
            emoji = String(c)
        }
    }
    var chs:String?
    var png:String?{
        didSet
        {
            imagePath = DLEmoticonPage.bundlePath + "/\(id!)/\(png!)"
        }
    }
    
    var imagePath:String?
    
    /// 表情被使用的次数
    var times: Int = 0
    
    /// emoji的字符串
    var emoji: String?
    
    var id:String?
    
    init(id: String,dic:[String:AnyObject])
    {
        self.id = id
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    var removeEmoticon = false
    init(removeEmoticon:Bool){
        self.removeEmoticon = removeEmoticon
        super.init()
    }
    
   override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description:String{
        return ("\n\t\t表情模型: \(code), \(chs), \(png)")
    }
    
}
